package com.person.jc.service.security;

import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.person.jc.service.Service;

public class TsUserVclService extends Service {
	
public static final TsUserVclService me = new TsUserVclService();
	
	@Before(Tx.class)
	public void saveUserVcl(Map<String, Object> map) {
		final String userId = String.valueOf(map.get("userId"));
		final String[]  menuIds = (String[])map.get("menuId");
		String sql = "delete from ts_user_menu_vcl where user_id = ?";
		Db.update(sql, userId);
		sql =  "insert into ts_user_menu_vcl(user_id,menu_id)";
		sql += " values";
		sql += " (?, ?)";
		Object[][] obj = new Object[menuIds.length][2];
		for (int i = 0; i < menuIds.length; i++) {
				obj[i][0] = userId;
				obj[i][1] = menuIds[i];
		}
		Db.batch(sql, obj, menuIds.length);
		super.setCRUD("用户权限管理", "C", "保存用户对应权限，用户"+userId);
	}
}
